package cn.superchart.module.menu.param;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.parser.NodeParser;
import cn.hutool.core.map.MapUtil;

import java.util.Map;

public class ScNodeParser<T> implements NodeParser<TreeNode<T>, T> {


    @Override
    public void parse(TreeNode<T> treeNode, Tree<T> tree) {
        if(treeNode instanceof ScTreeNode scTreeNode){
            tree.setId(treeNode.getId());
            tree.setParentId(treeNode.getParentId());
            tree.setWeight(treeNode.getWeight());
            tree.setName(treeNode.getName());
            Map<String, Object> extra = treeNode.getExtra();
            extra.put("menuName", scTreeNode.getAttributes().getMenuName());
            extra.put("menuEnable", scTreeNode.getAttributes().getEnable());
            extra.put("menuType", scTreeNode.getAttributes().getMenuType());
            extra.put("menuPath", scTreeNode.getAttributes().getMenuPath());
            if (MapUtil.isNotEmpty(extra)) {
                extra.forEach(tree::putExtra);
            }

        }
    }
}
